<script setup lang="ts">
import {defineExpose, defineProps, reactive, ref} from "vue";
import {
  AddSecretKey,
  UpdateText,
  GetSecretKeyList,
  GetTextContent,
  GetTextList
} from "../../../../wailsjs/go/view/SecretText";
import {base, tables} from "../../../../wailsjs/go/models.ts";


const props = defineProps({
  onLoadSecretTextList: {
    type: Function,
    required: true
  }
})


const dialogVisible = ref(false)
const editForm = reactive<base.UpdateSecretText>({
  id:0,
  title: "",
  label: "",
  adminKey: "",
  prompt: "",
  isPrivate: false,
  currentAdminKey:""
})
const keyList = ref<{}[]>([])

const clickSubBtn = ()=>{
  UpdateText(editForm).then(()=>{
    dialogVisible.value = false
    props.onLoadSecretTextList()
  })
}
const onDialogOpened = ()=>{
  GetSecretKeyList().then(res =>{
    keyList.value = []
    res.forEach(item=>{
      keyList.value.push({
        value: item.id,
        label: item.title,
      })
    })
  })
}


defineExpose({
  dialogVisible,
  editForm
})
</script>

<template>
  <el-dialog v-model="dialogVisible" @open="onDialogOpened">
    <el-form :model="editForm" label-width="auto" >
      <el-form-item label="标题">
        <el-input v-model="editForm.title" />
      </el-form-item>
      <el-form-item label="标签">
        <el-input v-model="editForm.label" />
      </el-form-item>
      <el-form-item label="密码提示">
        <el-input v-model="editForm.prompt" />
      </el-form-item>
      <el-form-item label="是否隐藏">
        <el-radio-group v-model="editForm.isPrivate">
          <el-radio :value="true">隐藏</el-radio>
          <el-radio :value="false">显示</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="旧管理密码">
        <el-input v-model="editForm.adminKey" show-password/>
      </el-form-item>
      <el-form-item label="新管理密码">
        <el-input v-model="editForm.currentAdminKey" show-password/>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible =false">取消</el-button>
        <el-button type="primary" @click="clickSubBtn">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>
